package hkr.budget;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseBuilder extends SQLiteOpenHelper{
	
	public static final String DATABASE_NAME = "budget_9.db";
	public static final int DATABASE_VERSION = 1;
	public static final String COLUMN_ID = "_id";
	public static final String DATE = "date";
	public static final String EXPENSE = "expense";
	public static final String CATEGORY = "category";
	public static final String PAYMENT_TYPE = "payment_type";
	public static final String PAYMENT_AMOUNT = "payment_amount";
	public static final String TABLE_BUDGET = "budget";
	private static final String DATABASE_BUILDER = "Database Builder";
	private static final String DATABASE_CREATE = "CREATE TABLE IF NOT EXISTS "
			+ TABLE_BUDGET +" (" + COLUMN_ID
			+ " INTEGER PRIMARY KEY, " + DATE
			+ " TEXT not null, " + EXPENSE
			+ " TEXT not null, " + CATEGORY 
			+ " TEXT not null, " + PAYMENT_TYPE
			+ " TEXT not null, " + PAYMENT_AMOUNT
			+ " REAL not null);";

	public DatabaseBuilder(Context context){
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		
	}
	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
		
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(DATABASE_BUILDER, "Upgrading database from version " + oldVersion + " to " + newVersion + " which will destroy all data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_BUDGET);
		
	}

}
